package com.ruoyi.kyjData.service.impl;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ExportWordUtils;
import com.ruoyi.common.utils.calculate.MotorUtils;
import com.ruoyi.kyjData.domain.pad.DataKyjModifyReqDTO;
import com.ruoyi.kyjData.domain.pad.KyjTaskResqDTO;
import com.ruoyi.kyjData.domain.plat.DataKyj;
import com.ruoyi.kyjData.mapper.DataKyjMapper;
import com.ruoyi.kyjData.service.IDataKyjService;
import com.ruoyi.task.domain.DataTaskResp;
import com.ruoyi.task.domain.entity.DataTaskEntity;
import com.ruoyi.task.mapper.DataTaskMapper;
import com.ruoyi.task.service.IDataTaskService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

/**
 * 空压机测试结果Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-11-16
 */
@Service
public class DataKyjServiceImpl implements IDataKyjService
{
    @Autowired(required = false)
    private DataKyjMapper dataKyjMapper;

    @Autowired(required = false)
    private IDataTaskService dataTaskService;

    /**
     * 查询空压机测试结果
     * 
     * @param kyjId 空压机测试结果主键
     * @return 空压机测试结果
     */
    @Override
    public DataKyj selectDataKyjByKyjId(Long kyjId)
    {
        return dataKyjMapper.selectDataKyjByKyjId(kyjId);
    }

    /**
     * 查询空压机测试结果列表
     * 
     * @param dataKyj 空压机测试结果
     * @return 空压机测试结果
     */
    @Override
    public List<DataKyj> selectDataKyjList(DataKyj dataKyj)
    {
        return dataKyjMapper.selectDataKyjList(dataKyj);
    }

    /**
     * 新增空压机测试结果
     * 
     * @param dataKyj 空压机测试结果
     * @return 结果
     */
    @Override
    public int insertDataKyj(DataKyj dataKyj)
    {
        dataKyj.setCreateTime(DateUtils.getNowDate());
        return dataKyjMapper.insertDataKyj(dataKyj);
    }

    /**
     * 修改空压机测试结果
     * 
     * @param dataKyj 空压机测试结果
     * @return 结果
     */
    @Override
    public int updateDataKyj(DataKyj dataKyj)
    {
        dataKyj.setUpdateTime(DateUtils.getNowDate());
        return dataKyjMapper.updateDataKyj(dataKyj);
    }

    /**
     * 批量删除空压机测试结果
     * 
     * @param kyjIds 需要删除的空压机测试结果主键
     * @return 结果
     */
    @Override
    public int deleteDataKyjByKyjIds(Long[] kyjIds)
    {
        return dataKyjMapper.deleteDataKyjByKyjIds(kyjIds);
    }

    /**
     * 删除空压机测试结果信息
     * 
     * @param kyjId 空压机测试结果主键
     * @return 结果
     */
    @Override
    public int deleteDataKyjByKyjId(Long kyjId)
    {
        return dataKyjMapper.deleteDataKyjByKyjId(kyjId);
    }

    /**
     * 根据任务id删除空压机测试结果数据
     * @param dataTaskId
     * @return
     */
    @Override
    public int deleteDataKyjByDataTaskId(Long dataTaskId) {
        return dataKyjMapper.deleteDataKyjByDataTaskId(dataTaskId);
    }

    /**
     * 批量新增空压机测试数据
     * @param list
     * @return
     */
    @Override
    public int batchDataKyj(List<DataKyj> list) {
        return dataKyjMapper.batchDataKyj(list);
    }

    /**
     * 根据任务id查询所有空压机数据
     * @param dataTaskId
     * @return
     */
    @Override
    @Async("threadPoolKy")
    public Future<List<DataKyj>> selectAllByDataTaskId(Long dataTaskId) {
        return new AsyncResult<>(dataKyjMapper.selectAllByDataTaskId(dataTaskId));
    }

    /**
     * 根据任务Id获取空压机任务数据
     *
     * @param dataTaskId
     */
    @Override
    @Async("threadPoolKy")
    public KyjTaskResqDTO selectKyjTaskByDataTaskId(Long dataTaskId) throws ExecutionException, InterruptedException {
        long startTime = System.currentTimeMillis();
        Future<DataTaskEntity> taskFuture = dataTaskService.selectDataTask(dataTaskId);
        Future<List<DataKyj>> resultListFuture = selectAllByDataTaskId(dataTaskId);
        KyjTaskResqDTO kyjTaskDTO = new KyjTaskResqDTO();
        boolean isGetDataTaskEntity = false;
        boolean isGetDataKyjEntityList = false;
        while (!isGetDataTaskEntity || !isGetDataKyjEntityList) {
            Thread.sleep(10);
            if (taskFuture.isDone() || taskFuture.isCancelled()) {
                isGetDataTaskEntity = true;
                if (taskFuture.isDone()) {
                    DataTaskEntity dataTaskEntity = taskFuture.get();
                    kyjTaskDTO.setDataTaskEntity(dataTaskEntity);
                }
            }
            if (resultListFuture.isDone() || resultListFuture.isCancelled()) {
                isGetDataKyjEntityList = true;
                if (resultListFuture.isDone()) {
                    List<DataKyj> dataShbEntityList = resultListFuture.get();
                    if (!CollectionUtils.isEmpty(dataShbEntityList)) {
                        dataShbEntityList.forEach(item -> {
                            item.setPjfl(getPjFl(item));
                            item.setPjwd(getPjWd(item));
                        });
                        kyjTaskDTO.getResultList().addAll(dataShbEntityList);
                    }
                }
            }
        }
        System.out.println("kyjTaskDTO = 空压机机测试数据数据查询用时 " + (System.currentTimeMillis() - startTime));
        return kyjTaskDTO;
    }

    /**
     * 平均风量
     */
    private String getPjFl(DataKyj dataKyj) {
        //平均风速
        float pjfs0 = StringUtils.isNotEmpty(dataKyj.getResPjfs0()) ? Float.parseFloat(dataKyj.getResPjfs0()) : 0;
        float pjfs1 = StringUtils.isNotEmpty(dataKyj.getResPjfs1()) ? Float.parseFloat(dataKyj.getResPjfs1()) : 0;
        float pjfs2 = StringUtils.isNotEmpty(dataKyj.getResPjfs2()) ? Float.parseFloat(dataKyj.getResPjfs2()) : 0;
        float pjfs3 = StringUtils.isNotEmpty(dataKyj.getResPjfs3()) ? Float.parseFloat(dataKyj.getResPjfs3()) : 0;
        float tfgmj0 = StringUtils.isNotEmpty(dataKyj.getTfgmj1()) ? Float.parseFloat(dataKyj.getTfgmj1()) :  0;
        float tfgmj1 = StringUtils.isNotEmpty(dataKyj.getTfgmj2()) ? Float.parseFloat(dataKyj.getTfgmj2()) : 0;
        float tfgmj2 = StringUtils.isNotEmpty(dataKyj.getTfgmj3()) ? Float.parseFloat(dataKyj.getTfgmj3()) : 0;
        float tfgmj3 = StringUtils.isNotEmpty(dataKyj.getTfgmj4()) ? Float.parseFloat(dataKyj.getTfgmj4()) : 0;
        float pjfl = tfgmj0 * pjfs0 + tfgmj1 * pjfs1 + tfgmj2 * pjfs2 + tfgmj3 * pjfs3;
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return pjfl == 0 ? "--" : (decimalFormat.format(pjfl));
    }


    /**
     * 平均温度
     */
    private String getPjWd(DataKyj dataKyj) {
        //平均温度
        float pjwd0 = StringUtils.isNotEmpty(dataKyj.getResPjwd0()) ? Float.parseFloat(dataKyj.getResPjwd0()) : 0;
        float pjwd1 = StringUtils.isNotEmpty(dataKyj.getResPjwd1()) ? Float.parseFloat(dataKyj.getResPjwd1()) : 0;
        float pjwd2 = StringUtils.isNotEmpty(dataKyj.getResPjwd2()) ? Float.parseFloat(dataKyj.getResPjwd2()) : 0;
        float pjwd3 = StringUtils.isNotEmpty(dataKyj.getResPjwd3()) ? Float.parseFloat(dataKyj.getResPjwd3()) : 0;
        int length = 0;
        float wdSum = 0;
        if (pjwd0 != 0) {
            wdSum += pjwd0;
            length++;
        }
        if (pjwd1 != 0) {
            wdSum += pjwd1;
            length++;
        }
        if (pjwd2 != 0) {
            wdSum += pjwd2;
            length++;
        }
        if (pjwd3 != 0) {
            wdSum += pjwd3;
            length++;
        }
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return length == 0 ? "--" : (decimalFormat.format(wdSum / length));

    }

    /**
     * 批量更新空压机数据
     * @param resultList
     * @return
     */
    @Override
    public int updateBatch(List<DataKyj> resultList) {
        return dataKyjMapper.updateBatch(resultList);
    }

    /**
     * 修改测试数据状态2
     *
     * @param dataTaskId
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateDataKyjByDataTaskId(Long dataTaskId) {
        //变更任务状态
        try {
            Long[] dataTaskIds = new Long[] {dataTaskId};
            dataTaskService.deleteDataTaskByDataTaskIds(dataTaskIds, "004");
        }catch (Exception e){
            e.printStackTrace();
        }
        //变更所有任务下数据
        return dataKyjMapper.updateDataKyjByDataTaskId(dataTaskId);
    }


    /**
     * 修改测试数据状态变更2
     *
     * @param dataTaskId
     * @param kyjId
     */
    @Override
    public int updateDataKyjByHjId(Long dataTaskId, Long kyjId) {
        return dataKyjMapper.updateDataKyjByKyjId(dataTaskId, kyjId);
    }

    /**
     * 空压机参数调整
     * @param dataKyjModifyReqDTO
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public DataKyj modify(DataKyjModifyReqDTO dataKyjModifyReqDTO) {
        DataKyj dataKyj = dataKyjMapper.selectDataKyjByKyjId(dataKyjModifyReqDTO.getResId());
        //电机参数计算
        if(StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResPjdy()) || StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResPjdl()) || StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResGlys())) {
            //平均电压计算、平均电流计算、功率因数计算
            dataKyj = getPower(dataKyjModifyReqDTO, dataKyjModifyReqDTO.getResId());
            //工序耗能更改
            String gxhn = getGxhn(dataKyj);
            if(StringUtils.isNotEmpty(gxhn)) {
                dataKyj.setResGxhn(gxhn);
            }
            //比功率
            String bgl = getBgl(dataKyj);
            if(StringUtils.isNotEmpty(bgl)) {
                dataKyj.setResBgl(bgl);
            }
        }
        //温度风速参数计算
        if(StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResPjfs0()) || StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResPjfs1()) || StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResPjfs2()) || StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResPjfs3()) || StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResPjwd0()) || StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResPjwd1()) || StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResPjwd2()) || StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResPjwd3())) {
            //标准排气量
            String bzpq = getBzpq(dataKyj);
            if(StringUtils.isNotEmpty(bzpq)) {
                dataKyj.setResBzpql(bzpq);
            }
            //排气效率
            String pqxl = getPqxl(dataKyj);
            if(StringUtils.isNotEmpty(pqxl)) {
                dataKyj.setResPqxl(pqxl);
            }
            //比功率
            String bgl = getBgl(dataKyj);
            if(StringUtils.isNotEmpty(bgl)) {
                dataKyj.setResBgl(bgl);
            }
            //工序耗能更改
            String gxhn = getGxhn(dataKyj);
            if(StringUtils.isNotEmpty(gxhn)) {
                dataKyj.setResGxhn(gxhn);
            }
        }
        //变更一级气压、二级气压、一级温度、二级温度
        if(StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResYjyl()) || StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResEjyl()) ||StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResYjwd()) ||StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResEjwd())) {
            if(StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResYjyl())) {
                dataKyj.setResYjyl(dataKyjModifyReqDTO.getResYjyl());
            }
            if(StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResEjyl())) {
                dataKyj.setResEjyl(dataKyjModifyReqDTO.getResEjyl());
            }
            if(StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResYjwd())) {
                dataKyj.setResYjwd(dataKyjModifyReqDTO.getResYjwd());
            }
            if(StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResEjwd())) {
                dataKyj.setResEjwd(dataKyjModifyReqDTO.getResEjwd());
            }
        }
        //数据更新
        dataKyjMapper.updateDataKyj(dataKyj);
        return dataKyj;
    }

    /**
     * 空压机报告导入
     *
     */
    @Override
    public String dataKyjImportReport(DataKyj dataKyj) {
        // 报告模板名称
        String template = dataKyj.getTempId();
        //测试任务信息
        DataTaskEntity dataTaskEntity = dataTaskService.selectDataTaskByDataTaskId(dataKyj.getDataTaskId());
        Map<String, Object> params = new HashMap<>();
        /* ===========  测试任务信息 */
        if (dataTaskEntity != null) {
            params.put("受检单位", dataTaskEntity.getShjdw());
            params.put("设备名称", dataTaskEntity.getShbbh());
            params.put("检测日期", DateUtils.dateTime(dataTaskEntity.getTaskCreateTime()));
            params.put("主检人员", dataTaskEntity.getZhjxm());
            params.put("测试人员", dataTaskEntity.getCshry());
        }
        /* ===========  参数、结果 */
        if (dataKyj != null) {
            params.put("容积流量", dataKyj.getRjll());
            params.put("二级压力", dataKyj.getResEjyl());
            params.put("轴功率", dataKyj.getResZgl());
            params.put("比功率", dataKyj.getResBgl());
            params.put("大气压力", dataKyj.getResHjdqy());
            params.put("大气温度", dataKyj.getResHjwd());
            params.put("一级温度", dataKyj.getResYjwd());
            params.put("二级温度", dataKyj.getResEjwd());
            params.put("一级排气压力", dataKyj.getResYjyl());
            params.put("二级排气压力", dataKyj.getResEjyl());
            params.put("电压", dataKyj.getResPjdy());
            params.put("电流", dataKyj.getResPjdl());
            params.put("实测排气量", dataKyj.getResScpql());
            params.put("工序耗能", dataKyj.getResGxhn());
        }
        String docRootPath = RuoYiConfig.getProfile() + RuoYiConfig.getDocumentPath() + "/";
        String docFileName = System.currentTimeMillis() + "-kyj.docx";
        boolean isOk = ExportWordUtils.exportWord(RuoYiConfig.getProfile() + RuoYiConfig.getTemplatePath() + "/" + template, docRootPath, docFileName, params);
        System.out.println("isOK: 生成测试报告" + isOk + " docFileName: " + docFileName);
        if(isOk) {
            return "/profile/document/" + docFileName;
        }else {
            return "";
        }
    }

    /**
     * 工序耗能
     * @param dataKyj
     * @return
     */
    private String getGxhn(DataKyj dataKyj) {
        if (StringUtils.isNotEmpty(dataKyj.getResEjyl()) && StringUtils.isNotEmpty(dataKyj.getResBzpql()) && StringUtils.isNotEmpty(dataKyj.getResDjgl())) {
            float bzpql = Float.parseFloat(dataKyj.getResBzpql());
            if (bzpql != 0) {
                float ejyl = Float.parseFloat(dataKyj.getResEjyl());
                float djgl = Float.parseFloat(dataKyj.getResDjgl());
                float a1 = 2.398f * djgl;
                float b1 = (float) (((Math.log(10f * ejyl) / Math.log(Math.E))) * bzpql * 60f);
                float gxhn = a1 / b1;
                return String.valueOf(gxhn);
            }
        }
        return "";
    }

    /**
     * 比功率
     * @param dataKyj
     * @return
     */
    private String getBgl(DataKyj dataKyj) {
        if (StringUtils.isNotEmpty(dataKyj.getResScpql()) && StringUtils.isNotEmpty(dataKyj.getResZgl())) {
            float scpql = Float.parseFloat(dataKyj.getResScpql());
            if (scpql != 0) {
                float zgl = Float.parseFloat(dataKyj.getResZgl());
                float bgl = zgl / scpql;
                return String.valueOf(bgl);
            }
        }
        return "";
    }

    /**
     * 计算电机
     */
    private DataKyj getPower(DataKyjModifyReqDTO dataKyjModifyReqDTO, Long kyjId) {
        //根据测试项id获取详情
        DataKyj dataKyj = dataKyjMapper.selectDataKyjByKyjId(kyjId);
        DecimalFormat df2 = new DecimalFormat("0.00");;
        //A相电流
        float aA = dataKyj.getResAa().isEmpty() ? 0f : Float.parseFloat(dataKyj.getResAa());
        //B相电流
        float bA = dataKyj.getResBa().isEmpty() ? 0f : Float.parseFloat(dataKyj.getResBa());
        //C相电流
        float cA = dataKyj.getResCa().isEmpty() ? 0f : Float.parseFloat(dataKyj.getResCa());
        //AB线电压
        float abV = dataKyj.getResAbv().isEmpty() ? 0f : Float.parseFloat(dataKyj.getResAbv());
        //CA线电压
        float caV = dataKyj.getResCav().isEmpty() ? 0f : Float.parseFloat(dataKyj.getResCav());
        //BC线电压
        float bcV = dataKyj.getResBcv().isEmpty() ? 0f : Float.parseFloat(dataKyj.getResBcv());
        //平均电流
        float pjdl = dataKyj.getResPjdl().isEmpty() ? 0f : Float.parseFloat(dataKyj.getResPjdl());
        //平均电压
        float pjdy = dataKyj.getResPjdy().isEmpty() ? 0f : Float.parseFloat(dataKyj.getResPjdy());
        //查看变更的参数
        if(StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResPjdl())) {
            //变更平均电流
            float diffDL = Float.parseFloat(dataKyjModifyReqDTO.getResPjdl()) - pjdl;
            dataKyj.setResAa(String.valueOf(aA + diffDL));
            dataKyj.setResBa(String.valueOf(bA + diffDL));
            dataKyj.setResCa(String.valueOf(cA + diffDL));
            dataKyj.setResPjdl(dataKyjModifyReqDTO.getResPjdl());
        }
        if(StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResPjdy())) {
            //变更平均电压
            float diffDY = Float.parseFloat(dataKyjModifyReqDTO.getResPjdy()) - pjdy;
            dataKyj.setResAbv(String.valueOf(abV + diffDY));
            dataKyj.setResBcv(String.valueOf(bcV + diffDY));
            dataKyj.setResCav(String.valueOf(caV + diffDY));
            dataKyj.setResPjdy(dataKyjModifyReqDTO.getResPjdy());
        }
        if(StringUtils.isNotEmpty(dataKyjModifyReqDTO.getResGlys())) {
            //变更功率因数
            dataKyj.setResGlys(dataKyjModifyReqDTO.getResGlys());
        }
        // 如果功率因数为0 ，则赋值为1 ，否则无法计算
        if (dataKyj.getResGlys() == null || dataKyj.getResGlys().isEmpty() || Float.parseFloat(dataKyj.getResGlys()) == 0) {
            dataKyj.setResGlys(1 + "");
        }
        float szgl = ((Float.parseFloat(dataKyj.getResAa()) * Float.parseFloat(dataKyj.getResAbv())) + (Float.parseFloat(dataKyj.getResBa()) * Float.parseFloat(dataKyj.getResBcv())) + (Float.parseFloat(dataKyj.getResCa()) * Float.parseFloat(dataKyj.getResCav()))) / 1000;
        //计算公式是通过平均电流乘以平均电压乘以3
        //float szgl = (Float.parseFloat(dataKyj.getResPjdl()) * Float.parseFloat(dataKyj.getResPjdy())) * 3 /1000;
        float djgl = (szgl * Float.parseFloat(dataKyj.getResGlys())) / 1.732F;
        dataKyj.setResDjgl(String.valueOf(df2.format(djgl)));
        MotorUtils motorUtils = new MotorUtils(dataKyj.getResAbv(), dataKyj.getResBcv(), dataKyj.getResCav(), dataKyj.getResAa(), dataKyj.getResBa(), dataKyj.getResCa(), dataKyj.getResPjdy(), dataKyj.getResPjdl());
        Map<String, String> resMap = motorUtils.cal(dataKyjModifyReqDTO.getResPjdy(), dataKyjModifyReqDTO.getResPjdl(), dataKyjModifyReqDTO.getResGlys(), dataKyj.getCdxl(), dataKyj.getDjEddy(), dataKyj.getDjEddl(), dataKyj.getDjEdgl(), dataKyj.getDjEdxl(), dataKyj.getDjKzdl(), dataKyj.getDjKzgl(), dataKyj.getDjEdglys(), dataKyj.getDjJs(), dataKyj.getDjWgjjdl());
        dataKyj.setResYxzt(resMap.get("运行状态"));
        dataKyj.setResZgl(resMap.get("轴功率"));
        dataKyj.setResDjxl(resMap.get("电机效率"));
        dataKyj.setResZhxl(String.valueOf(Float.parseFloat(resMap.get("综合效率")) / 100f));
        dataKyj.setResFzxs(resMap.get("负载系数"));
        float edgl = Float.parseFloat(dataKyj.getDjEdgl());
        dataKyj.setResScgl(String.valueOf(edgl * Float.parseFloat(dataKyj.getResFzxs())));
        return dataKyj;
    }

    /**
     * 排气效率
     * @param dataKyj
     */
    private String getPqxl(DataKyj dataKyj) {
        if (!dataKyj.getResBzpql().isEmpty()) {
            float bzpql = Float.parseFloat(dataKyj.getResBzpql());
            //排气效率
            float pqxl = bzpql / Float.parseFloat(dataKyj.getRjll());
            pqxl = pqxl > 1 ? 1 : pqxl;
            return String.valueOf(pqxl);
        }
        return "";
    }

    /**
     * 实测排气量
     * @param dataKyj
     */
    private String getScpq(DataKyj dataKyj) {
        /*实测排气量*/
        float scpql;
        //平均风速
        float pjfs0 = StringUtils.isNotEmpty(dataKyj.getResPjfs0()) ? Float.parseFloat(dataKyj.getResPjfs0()) : 0;
        float pjfs1 = StringUtils.isNotEmpty(dataKyj.getResPjfs1()) ? Float.parseFloat(dataKyj.getResPjfs1()) : 0;
        float pjfs2 = StringUtils.isNotEmpty(dataKyj.getResPjfs2()) ? Float.parseFloat(dataKyj.getResPjfs2()) : 0;
        float pjfs3 = StringUtils.isNotEmpty(dataKyj.getResPjfs3()) ? Float.parseFloat(dataKyj.getResPjfs3()) : 0;

        //压风系数  0轴流式 1螺杆式 2离心式 3活塞式
        float yfxs = 0.88f;
        switch (dataKyj.getYffs()) {
            case "轴流式":
                break;
            case "螺杆式":
                yfxs = 0.95f;
                break;
            case "离心式":
                yfxs = 0.85f;
                break;
            case "活塞式":
                yfxs = 0.85f;
                break;
        }
        //通风面积
        float tfgmj1 = StringUtils.isNotEmpty(dataKyj.getTfgmj1()) ? 0 : Float.parseFloat(dataKyj.getTfgmj1());
        float tfgmj2 = StringUtils.isNotEmpty(dataKyj.getTfgmj2()) ? 0 : Float.parseFloat(dataKyj.getTfgmj2());
        float tfgmj3 = StringUtils.isNotEmpty(dataKyj.getTfgmj3()) ? 0 : Float.parseFloat(dataKyj.getTfgmj3());
        float tfgmj4 = StringUtils.isNotEmpty(dataKyj.getTfgmj4()) ? 0 : Float.parseFloat(dataKyj.getTfgmj4());

        scpql = (tfgmj1 * pjfs0 + tfgmj2 * pjfs1 + tfgmj3 * pjfs2 + tfgmj4 * pjfs3) * 60f * yfxs;
        if (scpql != 0) {
            //实测排气量
            return String.valueOf(scpql);
        }
        return "";
    }

    /**
     * 标准排气量
     * @param dataKyj
     * @return
     */
    private String getBzpq(DataKyj dataKyj) {
        float bzpql;
        //平均温度
        float pjwd0 = StringUtils.isNotEmpty(dataKyj.getResPjwd0()) ? Float.parseFloat(dataKyj.getResPjwd0()) : 0;
        float pjwd1 = StringUtils.isNotEmpty(dataKyj.getResPjwd1()) ? Float.parseFloat(dataKyj.getResPjwd1()) : 0;
        float pjwd2 = StringUtils.isNotEmpty(dataKyj.getResPjwd2()) ? Float.parseFloat(dataKyj.getResPjwd2()) : 0;
        float pjwd3 = StringUtils.isNotEmpty(dataKyj.getResPjwd3()) ? Float.parseFloat(dataKyj.getResPjwd3()) : 0;
        int pipeCount = Integer.parseInt(dataKyj.getCfdgs());
        if (StringUtils.isNotEmpty(dataKyj.getResHjdqy()) && StringUtils.isNotEmpty(dataKyj.getResScpql())) {
            float scpql = Float.parseFloat(dataKyj.getResScpql());
            float dqy = Float.parseFloat(dataKyj.getResHjdqy());
            float a = scpql * dqy * 100f * 293f;
            float b = 101330f * (273.15f + (pjwd0 + pjwd1 + pjwd2 + pjwd3) / pipeCount);
            bzpql = a / b;
            if (bzpql != 0) {
                return String.valueOf(bzpql);
            }
        }
        return "";
    }
}
